package my.framework.ssm.sample.common.exception;


import my.framework.ssm.sample.common.enums.ResultEnum;

/**
 * 系统级别异常
 *
 * @author NuKi
 * @date 2018/11/23 0023
 */
public class SystemException extends RuntimeException {
    private String code;
    private String message;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private void setCodeAndMessge(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 默认异常 {@link ResultEnum#ERROR}
     */
    public SystemException() {
        setCodeAndMessge(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage());
    }

    /**
     * 默认异常{@link ResultEnum#ERROR}
     *
     * @param message 自定义异常提示
     */
    public SystemException(String message) {
        super(message);
        setCodeAndMessge(ResultEnum.ERROR.getCode(), message);
    }

    /**
     *  选定异常类型，使用默认异常提示
     * @param resultType 异常类型
     */
    public SystemException(ResultEnum resultType) {
        setCodeAndMessge(resultType.getCode(), resultType.getMessage());
    }

    /**
     * 选定异常类型，自定义异常提示
     * @param message 自定义异常提示
     * @param resultType 异常类型
     */
    public SystemException(String message, ResultEnum resultType) {
        super(message);
        setCodeAndMessge(resultType.getCode(), message);
    }
}
